﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zhaoxi.AgileFramework.WebCore.LogExtend
{
    /// <summary>
    /// 扩展个方法，让ILoggerFactory去AddProvider
    /// </summary>
    public static class CustomColorConsoleLoggerExtensions
    {
        public static ILoggerFactory AddColorConsoleLogger(this ILoggerFactory loggerFactory, CustomColorConsoleLoggerConfiguration config)
        {
            loggerFactory.AddProvider(new CustomColorConsoleLoggerProvider(config));
            return loggerFactory;
        }
        public static ILoggerFactory AddColorConsoleLogger(this ILoggerFactory loggerFactory)
        {
            var config = new CustomColorConsoleLoggerConfiguration();
            return loggerFactory.AddColorConsoleLogger(config);
        }
        public static ILoggerFactory AddColorConsoleLogger(this ILoggerFactory loggerFactory, Action<CustomColorConsoleLoggerConfiguration> configure)
        {
            var config = new CustomColorConsoleLoggerConfiguration();
            configure(config);// 此处的委托就是为了修改参数的值
            return loggerFactory.AddColorConsoleLogger(config);
        }


        public static ILoggingBuilder AddColorConsoleLogger(this ILoggingBuilder builder)
        {
            CustomColorConsoleLoggerConfiguration options = new CustomColorConsoleLoggerConfiguration();
            return builder.AddColorConsoleLogger(options);
        }
        public static ILoggingBuilder AddColorConsoleLogger(this ILoggingBuilder builder, CustomColorConsoleLoggerConfiguration options)
        {
            builder.Services.AddSingleton((ILoggerProvider)new CustomColorConsoleLoggerProvider(options));
            return builder;
        }

    }
}
